import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.junit.Test;
import org.xml.sax.XMLReader;

import java.util.List;

/**
 * @author adong
 */
public class Dom4jDemo {
    @Test
    public void Test() throws DocumentException {
        SAXReader reader = new SAXReader();
        Document document = reader.read("student.xml");

        Element rootElement = document.getRootElement();

        List<Element> students = rootElement.elements("student");

        for(Element student: students){
            String name = student.elementText("name");
            int age =Integer.valueOf(student.elementText("age"));
            char sex = student.elementText("sex").charAt(0);
            System.out.println(new Students(name,age,sex).toString());
        }
    }
}
